﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DealerJudge.Data
{
    public class DatabaseConnection : IDatabaseConnection
    {
        private readonly IDbConnection _connection;
        private bool _disposed;

        internal DatabaseConnection(IDbConnection connection)
        {
            _disposed = false;
            _connection = connection;
        }
        public IDbConnection Connection
        {
            get { return _connection; }
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_connection != null)
                    {
                        _connection.Dispose();
                    }
                }
                _disposed = true;
            }
        }
        ~DatabaseConnection()
        {
            Dispose(false);
        }
    }
}
